package sicnu.cs.aps.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import sicnu.cs.aps.common.ResultInfo;
import sicnu.cs.aps.common.ResultInfoUtil;
import sicnu.cs.aps.domain.vo.SimpleUserDetailInfoVo;
import sicnu.cs.aps.service.IStudentInfoService;
import sicnu.cs.aps.service.ITeacherInfoService;
import sicnu.cs.aps.service.IUserInfoService;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author CaiKe
 * @date 2022/5/29 17:40
 */
@Slf4j
@RestController
@RequestMapping("/userinfo")
@RequiredArgsConstructor
@Api(tags = {"用户信息模块"})
public class UserInfoResource {

    private final IUserInfoService userInfoService;
    private final IStudentInfoService studentInfoService;
    private final ITeacherInfoService teacherInfoService;

    @GetMapping("")
    @ApiOperation("获取用户身份信息（JSON过的）")
    public ResultInfo<String> getJSONedUserInfo() {
        return ResultInfoUtil.buildSuccessWithStr(userInfoService.getCurrentJSONedUserInfo());
    }

    @GetMapping("/stu/simple")
    @ApiOperation("通过模糊查询获得学号和姓名")
    public ResultInfo<List<SimpleUserDetailInfoVo>> getSimpleStuInfo(@NotNull @RequestParam("condition") String condition) {
        return ResultInfoUtil.buildSuccess(studentInfoService.listStudentByCondition(condition));
    }

    @GetMapping("/teacher/simple")
    @ApiOperation("通过模糊查询获得学号和姓名")
    public ResultInfo<List<SimpleUserDetailInfoVo>> getSimpleTeacherInfo(@NotNull @RequestParam("condition") String condition) {
        return ResultInfoUtil.buildSuccess(teacherInfoService.listTeacherByCondition(condition));
    }


}